import React, { Component } from 'react';
class DemoSetStateAttr extends Component {
    state = { 
      userinfo: {
        role:'admin',
        age: 18,
        email: '123@163.com' // 修改邮箱
      }
    } 
    changeUserInfo = (email) => {
    //   this.setState({
    //      userinfo: {
    //        email: email
    //      }
    //   })
    let userinfo = this.state.userinfo
    userinfo.email = email
    this.setState({
        userinfo
     })
    }
    render() { 
        return (<div>
        <h3>8.1 修改state对象下面的某个属性</h3>
        <p>邮箱：{this.state.userinfo.email}</p>
        <button onClick={() => this.changeUserInfo('test@163.com')}>修改邮箱地址</button>
        </div>);
    }
}
 
export default DemoSetStateAttr;